using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using ExcellentProjectPlus.Infraestructura.Data.Cuestionarios.Modelo.Mapping;
using ExcellentProjectPlus.Dominio.Cuestionarios.Entidades;

namespace ExcellentProjectPlus.Infraestructura.Data.Cuestionarios.Modelo
{
    public partial class CuestionariosContext : DbContext
    {
        static CuestionariosContext()
        {
            Database.SetInitializer<CuestionariosContext>(null);
        }

        public CuestionariosContext()
            : base("Name=CuestionariosContext")
        {
        }

        public DbSet<Cuestionario> Cuestionarios { get; set; }
        public DbSet<Opcion> Opcions { get; set; }
        public DbSet<Pregunta> Preguntas { get; set; }
        public DbSet<PreguntaCuestionario> PreguntaCuestionarios { get; set; }
        public DbSet<Recurso> Recursos { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new CuestionarioMap());
            modelBuilder.Configurations.Add(new OpcionMap());
            modelBuilder.Configurations.Add(new PreguntaMap());
            modelBuilder.Configurations.Add(new PreguntaCuestionarioMap());
            modelBuilder.Configurations.Add(new RecursoMap());

        }

        public virtual void RegistrarRecursoPorIdPregunta(int idPregunta, int idRecurso)
        {
            ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand("DELETE [dbo].[RecursoPregunta] WHERE [IdPregunta] = " + idPregunta +"; INSERT INTO [dbo].[RecursoPregunta] ([IdPregunta],[IdRecurso])  VALUES (" + idPregunta + ", " + idRecurso + ")");
        }
    }
}
